package com.xbao.service.impl;

import com.xbao.dao.NotifySettingMapper;
import com.xbao.model.NotifySetting;
import com.xbao.model.req.NotifysettingReq;
import com.xbao.service.NotifysettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by qingshengzheng on 2019/1/20.
 */
@Service
public class NotifysettingServiceImpl implements NotifysettingService {
    @Autowired
    private NotifySettingMapper notifysettingMapper;

    @Override
    public void addSetting(NotifysettingReq notifysetting) {
        notifysettingMapper.insert(notifysetting);

    }

    @Override
    public void updateSettings(NotifysettingReq notifysetting) {
        NotifySetting o = notifysettingMapper.selectByPrimaryKey(notifysetting.getOrgid());
        if (o == null) {
            notifysetting.setCreatetime(System.currentTimeMillis());
            notifysetting.setUpdatetime(System.currentTimeMillis());
            notifysettingMapper.insert(notifysetting);
        } else {
            notifysetting.setUpdatetime(System.currentTimeMillis());
            notifysettingMapper.updateByPrimaryKeySelective(notifysetting);
        }


    }

    @Override
    public NotifySetting detail(NotifysettingReq notifysettingReq) {
        return notifysettingMapper.selectByPrimaryKey(notifysettingReq.getOrgid());
    }
}
